define(function (require, exports, module) {
    'use strict';
    var Backbone = require('backbone'),
        utils = require('js/utils/tools'),
        helper = require('js/utils/router'),
        path = 'js/apps/preset/',
        config = {
            'tab': {
                'order': '-updated_at'
            },
            'lottery': {
                'order': '-updated_at'
            },
            'shortcut':{

            },
            'banner': {
                'order': '-updated_at'
            },
            'discovery': {
                'order': '-updated_at'
            },
            'loading': {
                'order': '-updated_at'
            },
            'pay': {
                'order': '-updated_at'
            },
            'reward': {
                'order': '-updated_at'
            },
            'recommend': {
                'order': '-updated_at'
            },
            'float_icon': {
                'order': '-updated_at'
            },
            'chnlink': {
            }
        };

    exports.Router = Backbone.Router.extend({
        routes: {
            "preset/:key/(?*qs)": "pList",
            "preset/:key/:id/": "pDetail",
            "preset/(?*qs)": 'presetList',
            "preset/:id/": "presetDetail",
        },
        initialize: function () {
            require([path + 'preset'], function (view) {
                _.each(view.Pannels, function (cls) {
                    utils.loadTemplate(cls);
                });
            });
        },
        pList: function (key, qs) {
            if (config[key] == null && qs == null) return this.presetDetail(key);
            helper.commonList(key, qs, path, config);
        },
        pDetail: function(key, id){
            helper.commonDetail(key, id, path, config);
        },
        presetList: function (qs) {
            var key = utils.getCurrentKey(),
                align = localStorage.getItem(key + '_align') || 'c',
                params = helper.parseQs(qs);
            utils.setrs(align);
            require([path + 'preset'], function (view) {
                utils.loadTemplate(view.List, function () {
                    var page = new view.List(params);
                    page.render();
                });
            })
        },
        presetDetail: function (id) {
            utils.setrs('c');
            var params = {};
            if (id != 'add') params.id = id;
            require([path + 'preset'], function (view) {
                utils.loadTemplate(view.Detail, function () {
                    var page = new view.Detail(params);
                    page.render();
                });
            });
        },
    });
});
